<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/demo/demo.css">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/admin.css">
        <script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="__PUBLIC__/easyui/easyui-lang-zh_CN.js"></script>
        
        <style type="text/css">
		#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			color:#666;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
	</style>
    </head>
    <body>
        <div>
            <span>批量导入数据。注意使用标准模板</span>
            <form action="__APP__/Admin/DBase/staffinfo" method="post" 
                  enctype="multipart/form-data" >
                <!-- input type="text" name="name" / -->
                <input type="file" name="xls" />
                <input type="submit" value="导入" />
            </form>
        </div>

        <table id="dg" class="easyui-datagrid" toolbar="#toolbar"
               style="width:760px;height:360px" data-options="
               url:'__APP__/Admin/DBase/stafflist',
               method:'get',                                
               singleSelect:true,
               autoRowHeight:false,
               pagination:true,
               pageSize:10">
            <thead>
                <tr>
                    <th field="id" hidden="true">教工编号</th>
                    <th field="sid" width="180">教工编号</th>
                    <th field="name" width="180">教工姓名</th>
                    <th field="sex" width="80">教工性别</th>
                    <th field="did" width="80" >部门编号</th>
                    <th field="dep_name" width="100">所在部门</th>
                    <th field="role" width="80">是否教师</th>                    
                    <th field="status" width="80">在职在岗</th>                   
                </tr>
            </thead>
        </table>
<div id="toolbar">
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">编辑</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:500px;height:320px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
	<div class="ftitle">教工信息</div>
	<form id="fm" method="post">
		<input type="hidden" name="id" />		
		<div class="fitem">
			<label>教工编号:</label>
			<input name="sid" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>教工姓名:</label>
			<input name="name" class="easyui-validatebox" required="true">
		</div>	
		<div class="fitem">
			<label>教工性别:</label>
			<input name="sex" class="easyui-validatebox" required="true">
			<span>男：1； 女：0</span>
		</div>
		<div class="fitem">
			<label>所在部门:</label>
			<input name="did" class="easyui-validatebox" required="true">
			<!--select id="staff_dep" name="did" style="width:150px">				
			</select-->
		</div>		
		<div class="fitem">
			<label>是否教师:</label>
			<input name="role" >
			<span>教师：1； 其他：0</span>
		</div>
		<div class="fitem">
			<label>在职在岗:</label>
			<input name="status" >
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>     
<script type="text/javascript">
var url;
function newItem(){
    $('#dlg').dialog('open').dialog('setTitle','新增');
	$('#fm').form('clear');
	url = '__APP__/Admin/DBase/staff_newItem';
}       

function editItem(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
	$('#dlg').dialog('open').dialog('setTitle','修改');
	$('#fm').form('load',row);
	url = '__APP__/Admin/DBase/staff_editItem/id/'+row.id;
    }
}

function save(){
	$('#fm').form('submit',{
		url: url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){
			var result = eval('('+result+')');
			if (result.errorMsg){
				$.messager.show({
					title: '出错',
					msg: result.errorMsg
				});
			} else {
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the user data
			}
		}
	});
}           
function destroyItem(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('请确认','确定要删吗?',function(r){
			if (r){
				$.post('__APP__/Admin/DBase/staff_destroy/',{sid:row.sid},function(result){
					if (result.success){
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({	// show error message
							title: '出错',
							msg: result.errorMsg
						});
					}
				},'json');
			}
		});
	}
} 






</script>        
    </body>   
</html>